package com.github.wxpay.sdk;

import com.yykj.pay.server.constant.YyWxConfig;
import lombok.extern.slf4j.Slf4j;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

@Slf4j
public class WxConfig extends WXPayConfig {
	private String certFilePath;

	public void setCertFilePath(String certFilePath) {
		this.certFilePath = certFilePath;
	}

	@Override
	String getAppID() {
		return YyWxConfig.APP_ID;
	}

	@Override
	String getMchID() {
		return YyWxConfig.MCH_ID;
	}

	@Override
	String getKey() {
		return YyWxConfig.KEY;
	}

	@Override
	InputStream getCertStream() {
		try {
			return new FileInputStream(certFilePath);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			log.info("找不到证书文件 => {}", e.getMessage());
		}
		return null;
	}

	@Override
	IWXPayDomain getWXPayDomain() {
		return new IWXPayDomain() {
			@Override
			public void report(String domain, long elapsedTimeMillis, Exception ex) {

			}

			@Override
			public DomainInfo getDomain(WXPayConfig config) {
				return new DomainInfo(WXPayConstants.DOMAIN_API, true);
			}
		};
	}
}
